package com.ruoyi.web.controller;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.OfficialTrends;
import com.ruoyi.system.service.IOfficialTrendsService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 图文学习管理Controller
 *
 * @author ruoyi
 * @date 2022-08-27
 */
@Controller
@RequestMapping("/system/trends")
public class OfficialTrendsController extends BaseController {
    private String prefix = "system/trends";

    @Autowired
    private IOfficialTrendsService officialTrendsService;

    @RequiresPermissions("system:trends:view")
    @GetMapping()
    public String trends() {
        return prefix + "/trends";
    }

    /**
     * 查询图文学习管理列表
     */
//    @RequiresPermissions("system:trends:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(OfficialTrends officialTrends) {
        startPage();
        List<OfficialTrends> list = officialTrendsService.selectOfficialTrendsList(officialTrends);
        return getDataTable(list);
    }

    /**
     * 导出图文学习管理列表
     */
    @RequiresPermissions("system:trends:export")
    @Log(title = "图文学习管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(OfficialTrends officialTrends) {
        List<OfficialTrends> list = officialTrendsService.selectOfficialTrendsList(officialTrends);
        ExcelUtil<OfficialTrends> util = new ExcelUtil<OfficialTrends>(OfficialTrends.class);
        return util.exportExcel(list, "图文学习管理数据");
    }

    /**
     * 新增图文学习管理
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存图文学习管理
     */
    @RequiresPermissions("system:trends:add")
    @Log(title = "图文学习管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(OfficialTrends officialTrends) {
        return toAjax(officialTrendsService.insertOfficialTrends(officialTrends));
    }

    /**
     * 修改图文学习管理
     */
    @RequiresPermissions("system:trends:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap) {
        OfficialTrends officialTrends = officialTrendsService.selectOfficialTrendsById(id);
        mmap.put("officialTrends", officialTrends);
        return prefix + "/edit";
    }

    /**
     * 修改保存图文学习管理
     */
    @RequiresPermissions("system:trends:edit")
    @Log(title = "图文学习管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(OfficialTrends officialTrends) {
        return toAjax(officialTrendsService.updateOfficialTrends(officialTrends));
    }

    /**
     * 删除图文学习管理
     */
    @RequiresPermissions("system:trends:remove")
    @Log(title = "图文学习管理", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(officialTrendsService.deleteOfficialTrendsByIds(ids));
    }


    /**
     * 获取图文学习列表
     *
     * @param officialTrends
     * @return
     */
    @PostMapping("/GetList")
    @ResponseBody
    public AjaxResult GetList(OfficialTrends officialTrends) {
        return success(officialTrendsService.selectOfficialTrendsList(officialTrends));
    }

    @PostMapping("/Getitem")
    @ResponseBody
    public AjaxResult GetItem(@RequestParam("ID") Long Id) {
        return success(officialTrendsService.selectOfficialTrendsById(Id));
    }
}
